package com.tuzhi.gateway.controller;

import com.tuzhi.gateway.service.ResServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

@RequestMapping("/gateway")
@RestController
@Slf4j
public class GatewayController {

    @Autowired
    ResServiceImpl resServiceImpl;

    @GetMapping("clear/{cmd}")
    public String clearNotAuthUrl(@PathVariable("cmd") String cmd) {
        log.info("请求清除不校验权限");
        if (!"abu".equalsIgnoreCase(cmd)) {
            return "无权限";
        }
        resServiceImpl.clearNotAuthUrl();
        return "清除成功";
    }

    @GetMapping("show/{cmd}")
    public String showNotAuthUrl(@PathVariable("cmd") String cmd) {
        log.info("请求清除不校验权限");
        if (!"abu".equalsIgnoreCase(cmd)) {
            return "无权限";
        }
        Set<String> urls = resServiceImpl.getNonAuthUrl();
        StringBuilder sb = new StringBuilder();
        urls.forEach(item -> {
            sb.append(item).append(",");
        });
        return sb.toString();
    }

}
